import java.util.concurrent.CountDownLatch;

public class Demo44 {
    public static void main(String[] args) throws InterruptedException {
        CountDownLatch latch = new CountDownLatch(10);//线程个数
        for(int i = 0; i < 10; i++){
             int id = i;
             Thread t1 = new Thread(() -> {
                 System.out.println("线程启动 "+ id);
                 try {
                     Thread.sleep(3000);
                 } catch (InterruptedException e) {
                     throw new RuntimeException(e);
                 }
                 System.out.println("线程结束 "+ id);
                 latch.countDown();
             });
             t1.start();

        }
        //通过await等待所有线程结束
        latch.await();
        System.out.println("所有线程结束。。");
    }
}
